package com.example.shop_car_2208.adapter

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.shop_car_2208.R
import com.example.shop_car_2208.entity.Data
import com.example.shop_car_2208.utils.GlideUtils

/**
 * 商品多布局适配器
 */
class GoodsMultiAdapter:BaseMultiItemQuickAdapter<Data,BaseViewHolder>() {
    init {
        addItemType(0, R.layout.item_goods)
        addItemType(1, R.layout.item_goods)
    }
    override fun convert(holder: BaseViewHolder, item: Data) {
        when(holder.itemViewType){
            1->{
                holder.setText(R.id.good_tv,item.goods_desc)
                holder.setText(R.id.good_money,"单价${item.goods_default_price}")//不能直接item.goods_default_price会报错
                GlideUtils.loafImage(context,holder.getView(R.id.good_iv),item.goods_default_icon)
            }
            0->{
                holder.setText(R.id.good_tv,item.goods_desc)
                holder.setText(R.id.good_money,"${item.goods_default_price}元起")//不能直接item.goods_default_price会报错
                GlideUtils.loafImage(context,holder.getView(R.id.good_iv),item.goods_default_icon)
            }
        }
    }
}